package iterator;

class Node{
    private Object o;
    Node next;

    Node(Object o){
        this.o = o;
    }
}

public class LinkList_ implements Collection_ {
    private Node head;
    private Node tail;
    private int size = 0;

    @Override
    public Collection_ add(Object o) {
        Node n = new Node(o);
        n.next = null;

        if(head == null){
            head = n;
        }else{
            tail.next = n;
        }

        tail = n;

        size++;

        return this;
    }

    @Override
    public int size() {
        return size;
    }

    @Override
    public Iterator_ getIterator(){
        return new Iterator_() {
            private int readFlg = 0;
            private Node bl = head;
            @Override
            public boolean hasNext() {
                return readFlg < size;
            }

            @Override
            public Object next() {
                Node result = bl;
                bl = bl.next;
                readFlg ++;
                return result;
            }
        };
    }
}
